﻿using System;
using System.Text;
using System.Collections.Generic;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ExchangeHog.MessageParser;

namespace ExchangeHog.MessageParserTest
{
	/// <summary>
	/// Summary description for UnitTest1
	/// </summary>
	[TestClass]
	public class ParserTest
	{
		public ParserTest()
		{
		}

		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}

		#region Additional test attributes
		//
		// You can use the following additional attributes as you write your tests:
		//
		// Use ClassInitialize to run code before running the first test in the class
		// [ClassInitialize()]
		// public static void MyClassInitialize(TestContext testContext) { }
		//
		// Use ClassCleanup to run code after all tests in a class have run
		// [ClassCleanup()]
		// public static void MyClassCleanup() { }
		//
		// Use TestInitialize to run code before running each test 
		// [TestInitialize()]
		// public void MyTestInitialize() { }
		//
		// Use TestCleanup to run code after each test has run
		// [TestCleanup()]
		// public void MyTestCleanup() { }
		//
		#endregion

		[TestMethod]
		public void GeneralTest()
		{
			//
			// TODO: Add test logic here
			//
		}

		[TestMethod]
		public void TestMailbox()
		{
			Parser p = new Parser("abc@def.com");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual(theaddr.name, "abc@def.com");
		}

		[TestMethod]
		public void TestMailboxWithSpaces()
		{
			Parser p = new Parser("    abc    @		def.com		 ");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual(" abc @ def.com", theaddr.name);
		}

		[TestMethod]
		public void TestMailboxWithFWS()
		{
			Parser p = new Parser("    abc    @	\r\n	def.com		 ");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual(" abc @ def.com", theaddr.name);
		}

		[TestMethod]
		public void TestMailboxWithComments()
		{
			Parser p = new Parser("abc(Kuka)@(Kuka)def.com ");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual("abc@def.com", theaddr.name);
		}

		[TestMethod]
		public void TestMailboxWithSpacesAndComments()
		{
			Parser p = new Parser("abc (Kuka) @ (Kuka) def.com ");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual("abc @ def.com", theaddr.name);
		}

		[TestMethod]
		public void TestMailboxWithQuotedName()
		{
			Parser p = new Parser("\"Joe Q. Public\" <john.q.public@example.com>");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual("\"Joe Q. Public\" <john.q.public@example.com>", theaddr.name);
		}

		[TestMethod]
		public void TestMailboxWithAtomsName()
		{
			Parser p = new Parser("Mary Smith <mary@example.net>");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual("Mary Smith <mary@example.net>", theaddr.name);
		}

		[TestMethod]
		public void TestMailboxWithQuotedName1()
		{
			Parser p = new Parser("\"Mary Smith: Personal Account\" <smith@home.example>");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual("\"Mary Smith: Personal Account\" <smith@home.example>", theaddr.name);
		}

		[TestMethod]
		[ExpectedException(typeof(LexerException), "Unrecognized token at '.'")]
		public void TestObsoleteMailboxWithCommentsInAddress()
		{
			Parser p = new Parser("John Doe <jdoe@machine(comment).  example>");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual("John Doe <jdoe@machine. example>", theaddr.name);
		}

		[TestMethod]
		[ExpectedException(typeof(LexerException), "Atom character expected instead of ' '")]
		public void TestObsoleteMailboxWithoutQuotesAroundDot()
		{
			Parser p = new Parser("Joe Q. Public <john.q.public@example.com>");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual("Joe Q. Public <john.q.public@example.com>", theaddr.name);
		}

		[TestMethod]
		public void TestMailboxWithCommentsInDisplayNameAndAngleAddr()
		{
			Parser p = new Parser("Pete(A nice \\) chap) <pete(his account)@silly.test(his host)>");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual("Pete <pete@silly.test>", theaddr.name);
		}

		[TestMethod]
		public void TestMailboxWithBigGroup()
		{
			Parser p = new Parser("A Group(Some people)\r\n" +
				"     :Chris Jones <c@(Chris's host.)public.example>,\r\n" +
				"            joe@example.org,\r\n" +
				"     John <jdoe@one.test> (my dear friend); (the end of the group)");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(3, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual("Chris Jones <c@public.example>", theaddr.name);
			addresses.MoveNext();
			theaddr = addresses.Current;
			Assert.AreEqual(" joe@example.org", theaddr.name);
			addresses.MoveNext();
			theaddr = addresses.Current;
			Assert.AreEqual(" John <jdoe@one.test>", theaddr.name);
		}

		[TestMethod]
		public void TestMailboxWithSmallgGroup()
		{
			Parser p = new Parser("(Empty list)(start)Hidden recipients  :(nobody(that I know))  ;");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual(null, theaddr.name);
		}

		[TestMethod]
		public void TestMailboxWithQuestionMarkAddr()
		{
			Parser p = new Parser("Who? <one@y.test>");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual("Who? <one@y.test>", theaddr.name);
		}

		[TestMethod]
		public void TestMailboxWithQuotedStringAddr()
		{
			Parser p = new Parser("\"Giant; \\\"Big\\\" Box\" <sysservices@example.net>");
			Parser.Addresses addrs = p.parseMailboxOrGroup();
			int cnt = 0;
			foreach (Parser.Address addr in addrs.addresses())
				cnt++;
			Assert.AreEqual(1, cnt, "Expected one address");
			IEnumerator<Parser.Address> addresses = addrs.addresses().GetEnumerator();
			addresses.MoveNext();
			Parser.Address theaddr = addresses.Current;
			Assert.AreEqual("\"Giant; \"Big\" Box\" <sysservices@example.net>", theaddr.name);
		}

		[TestMethod]
		public void TestMessage()
		{
			Parser p = new Parser(
@"From: John Doe <jdoe@machine.example>
To: Mary Smith <mary@example.net>
Subject: Saying Hello
Date: Fri, 21 Nov 1997 09:55:06 -0600
Message-ID: <1234@local.machine.example>

This is a message just to say hello.
So, ""Hello"".");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			String body = pm.body;
		}
		[TestMethod]
		public void TestMessageWithReferences()
		{
			Parser p = new Parser(
@"From: John Doe <jdoe@machine.example>
To: Mary Smith <mary@example.net>
Subject: Saying Hello
Date: Fri, 21 Nov 1997 09:55:06 -0600
In-Reply-To: <1230@ocal.machine.example> <1231@ocal.machine.example> 
Message-ID: <1234@local.machine.example>
References: <1233@ocal.machine.example> <1232@ocal.machine.example> 

This is a message just to say hello.
So, ""Hello"".");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			String body = pm.body;
		}

		[TestMethod]
		public void TestMessageWithReplyTo()
		{
			Parser p = new Parser(
@"From: Mary Smith <mary@example.net>
To: John Doe <jdoe@machine.example>
Reply-To: ""Mary Smith: Personal Account"" <smith@home.example>
Subject: Re: Saying Hello
Date: Fri, 21 Nov 1997 10:01:10 -0600
Message-ID: <3456@example.net>
In-Reply-To: <1234@local.machine.example>
References: <1234@local.machine.example>

This is a reply to your hello.
");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			String body = pm.body;
		}

		[TestMethod]
		public void TestMessageToGroup()
		{
			Parser p = new Parser(
@"From: Pete <pete@silly.example>
To: A Group:Ed Jones <c@a.test>,joe@where.test,John <jdoe@one.test>;
Cc: Undisclosed recipients:;
Date: Thu, 13 Feb 1969 23:32:54 -0330
Message-ID: <testabcd.1234@silly.example>

Testing.
");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			String body = pm.body;
		}

		[TestMethod]
		public void TestMessageWithOddSpacing()
		{
			Parser p = new Parser(
@"From: Pete(A nice \) chap) <pete(his account)@silly.test(his host)>
To:A Group(Some people)
        :Chris Jones <c@(Chris's host.)public.example>,
            joe@example.org,
     John <jdoe@one.test> (my dear friend); (the end of the group)
Cc:(Empty list)(start)Hidden recipients  :(nobody(that I know))  ;
Date: Thu,
         13
           Feb
             1969
         23:32
                  -0330 (Newfoundland Time)
Message-ID:              <testabcd.1234@silly.test>

Testing.	
");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			String body = pm.body;
		}

		[TestMethod]
		public void TestMessageWithEncodedWords()
		{
			Parser p = new Parser(
@"From: =?US-ASCII?Q?Keith_Moore?= <moore@cs.utk.edu>
To: =?ISO-8859-1?Q?Keld_J=F8rn_Simonsen?= <keld@dkuug.dk>
CC: =?ISO-8859-1?Q?Andr=E9?= Pirard <PIRARD@vm1.ulg.ac.be>
Subject: =?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=
     =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			while (iFields.MoveNext())
			{
				Parser.Field f = iFields.Current;
				Assert.IsNotNull(f);
				if (f != null && f.name == Parser.Field.Type.SUBJECT)
					Assert.AreEqual("If you can read this you understand the example.", f.value);
			}
			String body = pm.body;
		}

		[TestMethod]
		public void TestMessageWithEncodedWords1()
		{
			Parser p = new Parser(
@"From: =?ISO-8859-1?Q?Olle_J=E4rnefors?= <ojarnef@admin.kth.se>
To: ietf-822@dimacs.rutgers.edu, ojarnef@admin.kth.se
Subject: Time for ISO 10646?");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			String body = pm.body;
		}

		[TestMethod]
		public void TestMessageWithEncodedWords2()
		{
			Parser p = new Parser(
@"To: Dave Crocker <dcrocker@mordor.stanford.edu>
Cc: ietf-822@dimacs.rutgers.edu, paf@comsol.se
From: =?ISO-8859-1?Q?Patrik_F=E4ltstr=F6m?= <paf@nada.kth.se>
Subject: Re: RFC-HDR care and feeding");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			String body = pm.body;
		}

		[TestMethod]
		public void TestMessageWithEncodedWordsInComments()
		{
			Parser p = new Parser(
@"From: Nathaniel Borenstein <nsb@thumper.bellcore.com>
         (=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=)
To: Greg Vaudreuil <gvaudre@NRI.Reston.VA.US>, Ned Freed
      <ned@innosoft.com>, Keith Moore <moore@cs.utk.edu>
Subject: Test of new header generator
MIME-Version: 1.0
Content-type: text/plain; charset=ISO-8859-1");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			bool isMIMEVersionPresent = false;
			bool isContentTypePresent = false;
			bool isContentTypeParamPresent = false;
			while (iFields.MoveNext())
			{
				Parser.Field f = iFields.Current;
				Assert.IsNotNull(f);
				switch(f.name)
				{
					case Parser.Field.Type.MIME_VERSION: 
						Assert.AreEqual("1.0", f.value);
						isMIMEVersionPresent = true;
						break;
					case Parser.Field.Type.CONTENT_TYPE:
					{
						Parser.ContentTypeField fld = (Parser.ContentTypeField)f;
						Assert.AreEqual("text", fld.value.type);
						Assert.AreEqual("plain", fld.value.subtype);
						List<Tuple<String, String>> parameters = fld.value.parameters;
						IEnumerator<Tuple<String, String>> iP = parameters.GetEnumerator();
						while (iP.MoveNext())
						{
							Tuple<String, String> param = iP.Current;
							Assert.AreEqual("charset", param.Item1);
							Assert.AreEqual("ISO-8859-1", param.Item2);
							isContentTypeParamPresent = true;
						}
						isContentTypePresent = true;
						break;
					}
				}
			}
			Assert.IsTrue(isMIMEVersionPresent, "MIME-Version header was not processed");
			Assert.IsTrue(isContentTypePresent, "Content-Type header was not processed");
			Assert.IsTrue(isContentTypeParamPresent, "Content-Type charset param was not processed");
			String body = pm.body;
		}

		[TestMethod]
		public void TestMessageWithEncodedWordsInCommentsMIMEVersionWithTrailingComment()
		{
			Parser p = new Parser(
@"From: Nathaniel Borenstein <nsb@thumper.bellcore.com>
         (=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=)
To: Greg Vaudreuil <gvaudre@NRI.Reston.VA.US>, Ned Freed
      <ned@innosoft.com>, Keith Moore <moore@cs.utk.edu>
Subject: Test of new header generator
MIME-Version: 1.0 (produced by MetaSend Vx.x)
Content-type: text/plain; charset=ISO-8859-1");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			bool isMIMEVersionPresent = false;
			while (iFields.MoveNext())
			{
				Parser.Field f = iFields.Current;
				Assert.IsNotNull(f);
				if (f != null && f.name == Parser.Field.Type.MIME_VERSION)
				{
					Assert.AreEqual("1.0", f.value);
					isMIMEVersionPresent = true;
				}
			}
			Assert.IsTrue(isMIMEVersionPresent, "MIME-Version header was not processed");
			String body = pm.body;
		}

		[TestMethod]
		public void TestMessageWithEncodedWordsInCommentsMIMEVersionWithPrefixComment()
		{
			Parser p = new Parser(
@"From: Nathaniel Borenstein <nsb@thumper.bellcore.com>
         (=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=)
To: Greg Vaudreuil <gvaudre@NRI.Reston.VA.US>, Ned Freed
      <ned@innosoft.com>, Keith Moore <moore@cs.utk.edu>
Subject: Test of new header generator
MIME-Version: (produced by MetaSend Vx.x) 1.0
Content-type: text/plain; charset=ISO-8859-1");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			bool isMIMEVersionPresent = false;
			while (iFields.MoveNext())
			{
				Parser.Field f = iFields.Current;
				Assert.IsNotNull(f);
				if (f != null && f.name == Parser.Field.Type.MIME_VERSION)
				{
					Assert.AreEqual("1.0", f.value);
					isMIMEVersionPresent = true;
				}
			}
			Assert.IsTrue(isMIMEVersionPresent, "MIME-Version header was not processed");
			String body = pm.body;
		}

		[TestMethod]
		public void TestMessageWithEncodedWordsInCommentsMIMEVersionWithCommentsInTheMiddle()
		{
			Parser p = new Parser(
@"From: Nathaniel Borenstein <nsb@thumper.bellcore.com>
         (=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=)
To: Greg Vaudreuil <gvaudre@NRI.Reston.VA.US>, Ned Freed
      <ned@innosoft.com>, Keith Moore <moore@cs.utk.edu>
Subject: Test of new header generator
MIME-Version: 1.(produced by MetaSend Vx.x)0
Content-type: text/plain; charset=ISO-8859-1");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			bool isMIMEVersionPresent = false;
			while (iFields.MoveNext())
			{
				Parser.Field f = iFields.Current;
				Assert.IsNotNull(f);
				if (f != null && f.name == Parser.Field.Type.MIME_VERSION)
				{
					Assert.AreEqual("1.0", f.value);
					isMIMEVersionPresent = true;
				}
			}
			Assert.IsTrue(isMIMEVersionPresent, "MIME-Version header was not processed");
			String body = pm.body;
		}

		[TestMethod]
		public void TestFullblownMessage()
		{
			Parser p = new Parser(
@"Return-Path: <update+zj4ocf_6zcfy@facebookmail.com>
Delivered-To: alexander@aprelev.com
Received: from localhost (localhost [127.0.0.1])
	by minimac.aprelev.com (Postfix) with ESMTP id A98FD26DD63F
	for <alexander@aprelev.com>; Tue, 20 Dec 2011 21:49:42 -0500 (EST)
X-Virus-Scanned: amavisd-new at aprelev.com
Received: from minimac.aprelev.com ([127.0.0.1])
	by localhost (minimac.aprelev.com [127.0.0.1]) (amavisd-new, port 10024)
	with ESMTP id OBMRzg7lQiIP for <alexander@aprelev.com>;
	Tue, 20 Dec 2011 21:49:38 -0500 (EST)
Received: from mx-out.facebook.com (outmail012.snc4.facebook.com [66.220.144.146])
	by minimac.aprelev.com (Postfix) with ESMTP id DEA9A26DD62B
	for <alexander@aprelev.com>; Tue, 20 Dec 2011 21:49:37 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; d=facebookmail.com; s=s1024-2011-q2; c=relaxed/simple;
	q=dns/txt; i=@facebookmail.com; t=1324435774;
	h=From:Subject:Date:To:MIME-Version:Content-Type;
	bh=/7ctfWhSVFucXXUDfJ9gT8DKuONoFmTjr5UTHiRv/pE=;
	b=TxG/4HVYsQuIZQ9du4s1vtFOkJcO822wDxjcSs4chGftfVOyOlE7dp3Qo8XAtPqF
	GmzXrwW1KobVkeauhthkOqhABP/l33dB6GZhF95+8c6OzCzUZmePANXmMU79pL/r
	JOZkkV0hpsPIKumlQ9dOQpkGrja+PAOd9RWNF/3q+1c=;
Received: from [10.30.46.204] ([10.30.46.204:34217])
	by smout039.snc4.facebook.com (envelope-from <update+zj4ocf_6zcfy@facebookmail.com>)
	(ecelerity 2.2.2.45 r(34222M)) with ECSTREAM
	id 0E/03-24284-E3941FE4; Tue, 20 Dec 2011 18:49:34 -0800
X-Facebook: from zuckmail ([MTI3LjAuMC4x]) 
	by async.facebook.com with HTTP (ZuckMail);
Date: Tue, 20 Dec 2011 18:49:34 -0800
To: Alexander Aprelev <alexander@aprelev.com>
From: ""Facebook"" <update+zj4ocf_6zcfy@facebookmail.com>
Reply-to: Facebook <update+zj4ocf_6zcfy@facebookmail.com>
Subject: Alexander, you have notifications pending
Message-ID: <94a32e9d0c80d84c585f8c35e28b9887@async.facebook.com>
X-Priority: 3
X-Mailer: ZuckMail [version 1.00]
X-Facebook-Camp: engage_digest_email
X-Facebook-Notify: engage_digest_email; mailid=55b466cG5af31a634cbcG0Gd4
Errors-To: update+zj4ocf_6zcfy@facebookmail.com
X-FACEBOOK-PRIORITY: 1
MIME-Version: 1.0
Content-Type: multipart/alternative;
	boundary=""b1_94a32e9d0c80d84c585f8c35e28b9887""


--b1_94a32e9d0c80d84c585f8c35e28b9887
Content-Type: text/plain; charset=""UTF-8""
Content-Transfer-Encoding: quoted-printable

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
To login to Facebook, follow the link below:
http://www.facebook.com/n/?home.php&clk_loc=3D7&mid=3D55b466cG5af31a634cbc=
G0Gd4&bcode=3DjehavufC&n_m=3Dalexander%40aprelev.com
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D

Hi Alexander,

Here's some activity you may have missed on Facebook.

*  2 friend requests

Pavel Aprelev has posted statuses, photos and more on Facebook.

Thanks,
The Facebook Team

To login to Facebook, follow the link below:
http://www.facebook.com/n/?home.php&clk_loc=3D7&mid=3D55b466cG5af31a634cbc=
G0Gd4&bcode=3DjehavufC&n_m=3Dalexander%40aprelev.com

=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
This message was sent to alexander@aprelev.com. If you don't want to =
receive these emails from Facebook in the future, please follow the link =
below to unsubscribe.
http://www.facebook.com/o.php?k=3Da70863&u=3D100000166268092&mid=3D55b466c=
G5af31a634cbcG0Gd4
 Facebook, Inc. Attention: Department 415 P.O Box 10005 Palo Alto CA =
94303=20


--b1_94a32e9d0c80d84c585f8c35e28b9887
Content-Type: text/html; charset=""UTF-8""
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional =
//EN""><html><head><title>Facebook</title><meta http-equiv=3D""Content-Type"" =
content=3D""text/html; charset=3Dutf-8"" /></head><body style=3D""margin: 0; =
padding: 0;"" dir=3D""ltr""><table cellspacing=3D""0"" cellpadding=3D""0"" =
style=3D""border-collapse:collapse;width:98%;"" border=3D""0""><tr><td =
style=3D""font-size:12px;font-family:&#039;lucida =
grande&#039;,tahoma,verdana,arial,sans-serif;""><table cellspacing=3D""0"" =
cellpadding=3D""0"" style=3D""border-collapse:collapse;width:620px;""><tr><td =
style=3D""font-size:16px;font-family:&#039;lucida grande&#039;,tahoma,verda=
na,arial,sans-serif;background:#3b5998;color:#FFFFFF;font-weight:bold;vert=
ical-align:middle;letter-spacing:-0.03em;text-align:left;padding:10px 38px =
4px;""><a style=3D""text-decoration: none;"" href=3D""http://www.facebook.com/=
n/?home.php&amp;clk_loc=3D9&amp;mid=3D55b466cG5af31a634cbcG0Gd4&amp;bcode=
=3DjehavufC&amp;n_m=3Dalexander%40aprelev.com""><span style=3D""background:#=
3b5998;color:#FFFFFF;font-weight:bold;font-family:&#039;lucida =
grande&#039;,tahoma,verdana,arial,sans-serif;vertical-align:middle; =
font-size:16px;letter-spacing:-0.03em;text-align:left;"">facebook</span></a=
></td></tr></table><table cellspacing=3D""0"" cellpadding=3D""0"" =
style=3D""border-collapse:collapse;width:620px;""><tr><td =
style=3D""padding:10px 20px;background-color:#fff;border-left:1px solid =
#ccc;border-right:1px solid #ccc;border-top:1px solid =
#ccc;border-bottom:1px solid #ccc;line-height:16px;""><table =
cellspacing=3D""0"" cellpadding=3D""0"" width=3D""100%"" =
style=3D""border-collapse:collapse;""><tr><td =
style=3D""font-size:11px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;padding:10px =
20px;line-height:16px;width:620px;""><table cellspacing=3D""0"" =
cellpadding=3D""0"" style=3D""border-collapse:collapse;""><tr><td =
style=3D""font-size:13px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;"">Hi Alexander,</td></tr><tr><td =
style=3D""font-size:13px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;padding:10px 0 15px 0;"">Here's some activity =
you may have missed on Facebook.</td></tr><tr><td height=3D""1"" =
style=3D""font-size:11px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;background-color:#ccc;""></td></tr><tr><td =
style=3D""font-size:11px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;""><table cellspacing=3D""0"" cellpadding=3D""0"" =
style=3D""border-collapse:collapse;""><tr><td =
style=3D""font-size:11px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;padding:15px 20px 15px 0;""><table =
cellspacing=3D""0"" cellpadding=3D""0"" =
style=3D""border-collapse:collapse;""><tr><td valign=3D""top"" =
style=3D""padding-right: 5px;font-size: 0px;""><img =
src=3D""http://static.ak.fbcdn.net/rsrc.php/v1/yW/r/BwlAapiRmdD.png"" =
style=3D""border:0;"" /></td><td valign=3D""top""><a href=3D""http://www.facebo=
ok.com/n/?reqs.php&amp;clk_loc=3D1&amp;mid=3D55b466cG5af31a634cbcG0Gd4&amp=
;bcode=3DjehavufC&amp;n_m=3Dalexander%40aprelev.com"" =
style=3D""color:#3b5998;text-decoration:none;font-size:13px;"">2 friend =
requests</a></td></tr></table></td></tr></table></td></tr><tr><td =
height=3D""1"" style=3D""font-size:11px;font-family:&#039;lucida =
grande&#039;, tahoma, verdana, arial, =
sans-serif;background-color:#ccc;""></td></tr><tr><td =
style=3D""font-size:11px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;padding-top:15px;""><table cellspacing=3D""0"" =
cellpadding=3D""0"" style=3D""border-collapse:collapse;""><tr><td =
style=3D""font-size:0px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;padding:5px 5px 0px 0px;""><a =
href=3D""http://www.facebook.com/n/?pavpav&amp;clk_loc=3D2&amp;mid=3D55b466=
cG5af31a634cbcG0Gd4&amp;bcode=3DjehavufC&amp;n_m=3Dalexander%40aprelev.com=
"" style=3D""color:#3b5998;text-decoration:none;""><img width=3D""50"" =
height=3D""50"" src=3D""http://profile.ak.fbcdn.net/hprofile-ak-snc4/369623_6=
44942256_2087563204_q.jpg"" style=3D""border:0;"" =
/></a></td></tr></table></td></tr><tr><td =
style=3D""font-size:12px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;padding:10px 0 15px 0;""><a =
href=3D""http://www.facebook.com/n/?pavpav&amp;clk_loc=3D3&amp;mid=3D55b466=
cG5af31a634cbcG0Gd4&amp;bcode=3DjehavufC&amp;n_m=3Dalexander%40aprelev.com=
"" style=3D""color:#3b5998;text-decoration:none;"">Pavel Aprelev</a> has =
posted statuses, photos and more on Facebook.</td></tr><tr><td =
style=3D""font-size:11px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;padding:10px 0 15px 0;""><table =
cellspacing=3D""0"" cellpadding=3D""0"" border=3D""0"" =
style=3D""border-collapse:collapse;width:100%;""><tr><td =
style=3D""padding:10px;background-color:#f2f2f2;border-left:none;border-rig=
ht:none;border-top:1px solid #ccc;border-bottom:1px solid #ccc;""><table =
cellspacing=3D""0"" cellpadding=3D""0"" =
style=3D""border-collapse:collapse;""><tr><td =
style=3D""font-size:11px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;padding-right:10px;""><table cellspacing=3D""0"" =
cellpadding=3D""0"" style=3D""border-collapse:collapse;""><tr><td =
style=3D""border-width: 1px; border-style: solid; border-color: #29447E =
#29447E #1a356e; background-color: #5b74a8;""><table cellspacing=3D""0"" =
cellpadding=3D""0"" style=3D""border-collapse:collapse;""><tr><td =
style=3D""font-size:11px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;padding:4px 10px 5px;border-top:1px solid =
#8a9cc2;""><a href=3D""http://www.facebook.com/n/?home.php&amp;clk_loc=3D5&a=
mp;mid=3D55b466cG5af31a634cbcG0Gd4&amp;bcode=3DjehavufC&amp;n_m=3Dalexande=
r%40aprelev.com"" style=3D""color:#3b5998;text-decoration:none;""><span =
style=3D""font-weight: bold; color: #fff; font-size: 13px;"">Go To =
Facebook</span></a></td></tr></table></td></tr></table></td><td =
style=3D""font-size:11px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;""><table cellspacing=3D""0"" cellpadding=3D""0"" =
style=3D""border-collapse:collapse;""><tr><td style=3D""border-width: 1px; =
border-style: solid; border-color: #999 #999 #888; background-color: =
#eee;""><table cellspacing=3D""0"" cellpadding=3D""0"" =
style=3D""border-collapse:collapse;""><tr><td =
style=3D""font-size:11px;font-family:&#039;lucida grande&#039;, tahoma, =
verdana, arial, sans-serif;padding:4px 10px 5px;border-top:1px solid =
#fff;""><a href=3D""http://www.facebook.com/n/?notifications&amp;clk_loc=3D6=
&amp;mid=3D55b466cG5af31a634cbcG0Gd4&amp;bcode=3DjehavufC&amp;n_m=3Dalexan=
der%40aprelev.com"" style=3D""color:#3b5998;text-decoration:none;""><span =
style=3D""font-weight: bold; color: #333; font-size: 13px;"">See All =
Notifications</span></a></td></tr></table></td></tr></table></td></tr></ta=
ble></td></tr></table></td></tr></table></td></tr></table></td></tr></tabl=
e><table cellspacing=3D""0"" cellpadding=3D""0"" border=3D""0"" =
style=3D""border-collapse:collapse;width:620px;""><tr><td =
style=3D""padding:10px;background-color:#fff;border-left:none;border-right:=
none;border-top:none;border-bottom:none;font-size:11px;font-family:&#039;l=
ucida grande&#039;, tahoma, verdana, arial, =
sans-serif;color:#999999;border:none;"">This message was sent to =
alexander&#064;aprelev.com. If you don't want to receive these emails from =
Facebook in the future or have your email address used for friend =
suggestions, please click: <a href=3D""http://www.facebook.com/o.php?k=3Da7=
0863&amp;u=3D100000166268092&amp;mid=3D55b466cG5af31a634cbcG0Gd4"" =
style=3D""color:#3b5998;text-decoration:none;"">unsubscribe</a>.<br /> =
Facebook, Inc. Attention: Department 415 P.O Box 10005 Palo Alto CA 94303 =
</td></tr></table><span style=3D""width:620px;""><img src=3D""http://www.face=
book.com/email_open_log_pic.php?mid=3D55b466cG5af31a634cbcG0Gd4"" =
style=3D""border:0;width:1px;height:1px;"" /><bgsound src=3D""http://www.face=
book.com/email_open_log_pic.php?mid=3D55b466cG5af31a634cbcG0Gd4&s=3Da"" =
volume=3D""-10000""/></span></td></tr></table></body></html>



--b1_94a32e9d0c80d84c585f8c35e28b9887--

.
");

			Parser.Message pm = p.parseMessage();
			IEnumerator<Parser.Field> iFields = pm.fields.GetEnumerator();
			bool isMIMEVersionPresent = false;
			bool isContentTypePresent = false;
			bool isContentTypeParamPresent = false;
			while (iFields.MoveNext())
			{
				Parser.Field f = iFields.Current;
				Assert.IsNotNull(f);
				switch(f.name)
				{
					case Parser.Field.Type.MIME_VERSION: 
						Assert.AreEqual("1.0", f.value);
						isMIMEVersionPresent = true;
						break;
					case Parser.Field.Type.CONTENT_TYPE:
					{
						Parser.ContentTypeField fld = (Parser.ContentTypeField)f;
						Assert.AreEqual("multipart", fld.value.type);
						Assert.AreEqual("alternative", fld.value.subtype);
						List<Tuple<String, String>> parameters = fld.value.parameters;
						IEnumerator<Tuple<String, String>> iP = parameters.GetEnumerator();
						while (iP.MoveNext())
						{
							Tuple<String, String> param = iP.Current;
							Assert.AreEqual("boundary", param.Item1);
							Assert.AreEqual("b1_94a32e9d0c80d84c585f8c35e28b9887", param.Item2);
							isContentTypeParamPresent = true;
						}
						isContentTypePresent = true;
						break;
					}
				}
			}
			Assert.IsTrue(isMIMEVersionPresent, "MIME-Version header was not processed");
			Assert.IsTrue(isContentTypePresent, "Content-Type header was not processed");
			Assert.IsTrue(isContentTypeParamPresent, "Content-Type charset param was not processed");
			String body = pm.body;
		}
		
	}
}
